//
//  WJMeSearchCell.m
//  WJBSApp
//
//  Created by dllo on 16/7/16.
//  Copyright © 2016年 王景伟. All rights reserved.
//

#import "WJMeSearchCell.h"
#import "WJMeModel.h"

@interface WJMeSearchCell ()

@property (nonatomic,retain) WJBaseImageView *image_listImageView;

@property (nonatomic,retain) WJBaseLable *sub_numberLable; //订阅

@property (nonatomic,retain) WJBaseLable *rightLable;

@property (nonatomic,retain) UILabel *belowLable;

@end

@implementation WJMeSearchCell

-(void)dealloc
{
    [_image_listImageView release];
    [_theme_nameLable release];
    [_sub_numberLable release];
    [_rightLable release];
    [_belowLable release];
    [_model release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.image_listImageView = [[WJBaseImageView alloc]init];
        [self.contentView addSubview:self.image_listImageView];
        [_image_listImageView release];
        
        self.theme_nameLable = [[WJBaseLable alloc]init];
        [self.contentView addSubview:self.theme_nameLable];
        [_theme_nameLable release];
        
        self.sub_numberLable = [[WJBaseLable alloc]init];
        [self.contentView addSubview:self.sub_numberLable];
        [_sub_numberLable release];
        
        self.rightLable = [[WJBaseLable alloc]init];
        [self.contentView addSubview:self.rightLable];
        self.rightLable.text = @">";
        self.rightLable.textColor = [UIColor orangeColor];
        [_rightLable release];

        
        self.belowLable = [[UILabel alloc]init];
        [self.contentView addSubview:self.belowLable];
        self.belowLable.backgroundColor = [UIColor grayColor];
        [_belowLable release];
        
        
    }
    return self;
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.image_listImageView.frame = CGRectMake(10, 10, HEIGHT / 9 - 20,HEIGHT / 9 - 20);
    
    self.theme_nameLable.frame = CGRectMake(15 +  HEIGHT / 9 - 20, 10, 200, (HEIGHT / 9 - 20) / 2);
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    CGRect rect = [self.sub_numberLable.text boundingRectWithSize:CGSizeMake(1000, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.sub_numberLable.frame = CGRectMake(15 +  HEIGHT / 9 - 20, HEIGHT / 18, rect.size.width + 20, (HEIGHT / 9- 20) / 2 - 1);
    _sub_numberLable.font = [UIFont systemFontOfSize:14];
    
    
    self.rightLable.frame = CGRectMake(WIDTH * 6 / 7 - 10, (HEIGHT / 9 - 30) / 2, WIDTH / 7, 30);
    self.belowLable.frame = CGRectMake(0, HEIGHT/9 - 1, WIDTH , 1);
    
}

- (void)setModel:(WJMeModel *)model
{
    if (_model !=model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.image_listImageView sd_setImageWithURL:[NSURL URLWithString:model.image_list]];
    
//    self.theme_nameLable.text = model.theme_name;
    
    // 大于1万和小于1万显示不同
    
    if (model.sub_number >= 10000) {
        NSString *str = [NSString stringWithFormat:@"%.1f万人订阅",model.sub_number/10000.0];
        self.sub_numberLable.text = [str stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }else{
        self.sub_numberLable.text = [NSString stringWithFormat:@"%ld人订阅",(long)model.sub_number];
    }
    
    
    
}
@end
